<template>
	<view>
		<view class="star-container" v-if="star.length !== 0">
			<!-- 商品标题区域 -->
			<view class="star-title">
				<!-- 左侧图标 -->
				<uni-icons type="star" size="18"></uni-icons>
				<!-- 右侧文本 -->
				<text class="star-title-text">我的收藏</text>
			</view>
			<!-- 加入购物车商品列表 -->
			<uni-swipe-action>
				<block v-for="(item,i) in star" :key="i">
					<uni-swipe-action-item :right-options="options" @click="swiperItemClickHandler(item)">
						<my-goods :goods="item"></my-goods>
					</uni-swipe-action-item>
				</block>
			</uni-swipe-action>
		</view>
		<!-- 空白购物车区域 -->
		<view class="empty-star" v-else>
			<image src="../../static/cart_empty@2x.png" class="empty-img"></image>
			<text class="tip-text">空空如也~</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_cart', ['star'])
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d',
					}
				}]
			};
		},
		methods: {
			...mapMutations('m_cart', ['cancelStar']),
			swiperItemClickHandler(e) {
				this.cancelStar(e)
			}
		}
	}
</script>

<style lang="scss">
.star-container {
		padding-bottom: 50px;
	}

	.star-title {
		height: 40px;
		display: flex;
		align-items: center;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;
		background-color: #fff;

		.star-title-text {
			font-size: 14px;
			margin-left: 10px;
		}
	}

	.empty-star {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 150px;

		.empty-img {
			width: 90px;
			height: 90px;
		}

		.tip-text {
			font-size: 12px;
			color: gray;
			margin-top: 15px;
		}
	}
</style>
